# Utils used by the Magic Mod.
# Others Might want touse this too.
# Made by Lord Olleus
#Last edited 30th June 06

from CvPythonExtensions import *
import CvUtil
import sdToolKit

# globals
gc = CyGlobalContext()
sd = sdToolKit

#Returns a list which includes all the plots between (iX, iY) and (jX, jY). 
def PathList (iX, iY, jX, jY):
	PathList = []
	pMap = gc.getMap()
	pPlot = pMap.plot(iX, iY)
	PathList.append(pPlot)
	
	while  iX != jX or iY != jY:
		if iX > jX:
			iX -= 1
		
		elif iX < jX:
			iX += 1
			
		if iY > jY:
			iY -= 1
		
		elif iY < jY:
			iY += 1

		pLoopPlot = pMap.plot(iX, iY)
		PathList.append(pLoopPlot)	
			
	return PathList

def UnitSelectionPopup (pSpellUnit, iX, iY):
	iNumUnits = gc.getMap().plot(iX, iY).getNumUnits()
	if iNumUnits > 0:
		popupInfo = CyPopupInfo()
		popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
		popupInfo.setData1(iX)
		popupInfo.setData2(iY)
		popupInfo.setData3(pSpellUnit.getID())
		popupInfo.setText(str(pSpellUnit.getOwner()))
		popupInfo.setOnClickedPythonCallback("selectUnit")
		for iI in range(iNumUnits):
			pUnit = gc.getMap().plot(iX, iY).getUnit(iI)
			popupInfo.addPythonButton(pUnit.getName(), gc.getUnitInfo(pUnit.getUnitType()).getButton())
		popupInfo.addPopup(pSpellUnit.getOwner())
		return
	
def isEnemy(iPlayer1, iPlayer2):
	if iPlayer1 == iPlayer2:
		return True
	
	pTeam1 = gc.getTeam(gc.getPlayer(iPlayer1).getTeam())
	
	if pTeam1.isAtWar(gc.getPlayer(iPlayer2).getTeam()):
		return True
	
	return False
	
	
	
	
	
	
	
	
	